//
//  BN_Mine_TeacherBrowseCommentData.m
//  BabyNow
//
//  Created by 刘泽琛 on 14-6-6.
//  Copyright (c) 2014年 iMobile. All rights reserved.
//

#import "BN_Mine_TeacherBrowseCommentData.h"

@implementation BN_Mine_TeacherBrowseCommentData {
    BN_MyInfoHelper *myInfoHelper_;
    NSString *chilIdStr_;
}

- (id)initWithChilId:(NSString *)chilIdStr {
    
    if (self = [super init]) {
        myInfoHelper_ = [[BN_MyInfoHelper alloc]init];
        chilIdStr_ = chilIdStr;
        [self performSelectorInBackground:@selector(requestNetData_browseComment) withObject:nil];
    }
    return self;
}

- (void)toReloadList:(ReloadList) reLoadList {
    self.reloadList = reLoadList;
}

#pragma mark
#pragma mark UITableView Delegate

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 80;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.commentNetArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *identifier = @"identifier";
    BN_TeacherBrowseCommentListCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[[NSBundle mainBundle]loadNibNamed:@"BN_TeacherBrowseCommentListCell" owner:nil options:nil]objectAtIndex:0];
    }
    cell.contentLabel.text = self.commentNetArr[indexPath.row][@"evalCont"];
    
    cell.chilId = chilIdStr_;
    
    // 发布时间
    NSString *dateStr = self.commentNetArr[indexPath.row][@"evalDate"];
    NSRange rang = NSMakeRange(0, 19);
    NSString *strRang = [dateStr substringWithRange:rang];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    NSTimeZone *timeZone = [NSTimeZone localTimeZone];
    [formatter setTimeZone:timeZone];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSDate *dateTime = [formatter dateFromString:strRang];
    cell.timeLabel.text = [IMB_TimeFormatModel timeFormat:dateTime];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

#pragma mark
#pragma mark 网络请求

- (void)requestNetData_browseComment {
    
    __weak typeof(self) weakSelf = self;
    NSString *childId = chilIdStr_;
    myInfoHelper_.queryEvalListCompleteHandler = ^(id result,NSString *errMsg){
        if (errMsg) {
            // [blockSelf_ showTopMessage:errMsg];
            weakSelf.reloadList(NO);
        }else{
            weakSelf.commentNetArr = (NSArray *)result;
            weakSelf.reloadList(YES);
        }
    };
    [myInfoHelper_ refreshEvalList:childId];
}

- (void)dealloc
{
    myInfoHelper_ = nil;
    NSLog(@"老师查看周评列表释放...");
}
@end
